package com.example.tulingtest;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class test {

    public static void main(String[] args) throws Exception{
        DateFormat sf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

        List<Map<String,Object>> list=new ArrayList<>();
        Map<String,Object> h1=new HashMap<>();h1.put("status",0); h1.put("time","2019-12-4 15:35:33");
        Map<String,Object> h2=new HashMap<>();h2.put("status",1);h2.put("time","2019-12-1 15:35:33");
        Map<String,Object> h3=new HashMap<>();h3.put("status",2);h3.put("time","2019-12-3 15:35:33");
        Map<String,Object> h4=new HashMap<>();h4.put("status",1);h4.put("time","2019-12-6 15:35:33");

        list.add(h1);list.add(h2);list.add(h3);list.add(h4);

//
        System.out.println("=========================================");

        list.sort((a,b) ->(int)a.get("status")==2?-1:1);
        list.stream().forEach(n->{

            System.out.println(n);
        });

        System.out.println("=========================================");
        list.sort((c, d) -> DateUtil.parse(c.get("time").toString()).getTime() - DateUtil.parse(d.get("time").toString()).getTime() >= 0 ? -1 : 1);
        list.stream().forEach(n->{

            System.out.println(n);
        });


        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

        Stream<Map<String, Object>> stream = list.stream().sorted(
                (c, d) -> DateUtil.parse(c.get("time").toString()).getTime() - DateUtil.parse(d.get("time").toString()).getTime() >= 0 ? -1 : 1
        )
                .sorted(
                        (a, b) -> (int)a.get("status")==2?-1:1
        );

        List<Map<String, Object>> list2 = stream.collect(Collectors.toList());
        list2.stream().forEach(n->{
            System.out.println(n);
        });

        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        List<Map<String, Object>> maps = list2.subList(0, 2);
        maps.stream().forEach(n->{
            System.out.println(n);
        });
//o1.get("status")-o2.get("status")



    }

}
